package cn.jishiyu11.xeqb.utils

import android.annotation.SuppressLint

import java.text.SimpleDateFormat
import java.util.Date

/**
 * vvguoliang 2017-6-23
 * TimeUtils
 * 设置时间
 */
@SuppressLint("SimpleDateFormat")
class TimeUtils private constructor() {

    init {
        throw AssertionError()
    }

    companion object {

        val DEFAULT_DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
        val DATE_FORMAT_DATE = SimpleDateFormat("yyyy-MM-dd")
        val DATE_FORMAT_DATE2 = SimpleDateFormat("yyyyMMdd_HHmmss")
        private var lastClickTime: Long = 0

        /**
         * long time to string
         *
         * @param timeInMillis
         * @param dateFormat
         * @return
         */
        @JvmOverloads
        fun getTime(timeInMillis: Long, dateFormat: SimpleDateFormat = DEFAULT_DATE_FORMAT): String {
            return dateFormat.format(Date(timeInMillis))
        }

        /**
         * get current time in milliseconds
         *
         * @return
         */
        val currentTimeInLong: Long
            get() = System.currentTimeMillis()

        /**
         * get current time in milliseconds, format is [.DEFAULT_DATE_FORMAT]
         *
         * @return
         */
        val currentTimeInString: String
            get() = getTime(currentTimeInLong)

        /**
         * get current time in milliseconds, format is [.DEFAULT_DATE_FORMAT]
         *
         * @return
         */
        val currentTimeString: String
            get() = getTime(currentTimeInLong, DATE_FORMAT_DATE2)

        /**
         * get current time in milliseconds
         *
         * @return
         */
        fun getCurrentTimeInString(dateFormat: SimpleDateFormat): String {
            return getTime(currentTimeInLong, dateFormat)
        }

        val isFastDoubleClick: Boolean
            get() {
                val time = System.currentTimeMillis()
                val timeD = time - lastClickTime
                if (0 < timeD && timeD < 800) {
                    return true
                }
                lastClickTime = time
                return false
            }
    }
}
/**
 * long time to string, format is [.DEFAULT_DATE_FORMAT]
 *
 * @param timeInMillis
 * @return
 */
